;Explorer PC by Pablo Corro Cortez
;Http://www.geocities.com/xxideveloper
;Email:pablocortez@hotmail.com
vesa101h segment "CODE"
assume cs:vesa101h,ds:datasegment
putpixel PROC far
	mov di,win_relative_x1
	cmp di,win_relative_maxX
	jbe pp5tt
	mov win_relative_maxX,di
  pp5tt:cmp di,win_relative_startX
	jae pp4tt
	ret
  pp4tt:cmp di,win_relative_bottomX
	jae pp4ttb
	ret
  pp4ttb:cmp di,win_relative_topX
	jbe ppXtt
	ret
  ppXtt:sub di,win_relative_startX
	add di,win_absolute_x1
	cmp di,win_absolute_x2
	jbe pp7tt
	ret
  pp7tt:mov ax,win_relative_y1
	cmp ax,win_relative_maxY
	jbe pp6tt
	mov win_relative_maxY,ax
  pp6tt:cmp ax,win_relative_startY
	jae pp8tt
	ret
  pp8tt:cmp ax,win_relative_topY
	jbe pp10t
	ret
  pp10t:cmp win_putpixel_active,off
	jne pp11t
        ret
  pp11t:sub ax,win_relative_startY
	add ax,win_absolute_y1
	cmp ax,win_absolute_y2
	ja pp3tt
	cmp di,mouse_internal_x1
	jb out_101h
	cmp di,mouse_internal_x2
	ja out_101h
	cmp ax,mouse_internal_y1
	jb out_101h
	cmp ax,mouse_internal_y2
	ja out_101h
	mov cx,mouse_internal_pixels
	mov si,offset mouse_internal_data
	change_101h:
	cmp di,[si]
	jne change_err_101h
	cmp ax,[si+2]
	jne change_err_101h
		mov al,win_color
                cmp win_putpixel_eraser,off
                je pp_ok1
                mov al,0fh
       		pp_ok1:mov [si+5],al
                ret
	change_err_101h:
	add si,6
	loop change_101h
	out_101h:
	mov bx,640
	mul bx
	add ax,di
	adc dx,0
	mov si,ax
	cmp vesa_bank,dx
	je put_101h
	mov vesa_bank,dx
	mov cl,byte ptr vesa_WinGranularity
	shl dx,cl
	mov ax,4f05h
	xor bx,bx
	int 10h
	put_101h:
	mov al,win_color
        cmp win_putpixel_eraser,off
        je pp_ok2
        mov al,0fh
        pp_ok2:
        mov es:[si],al
  pp3tt:ret
putpixel ENDp
clrscr   PROC far
	 cli
         pusha
	 mov al,win_color
         mov ah,al
         mov di,ax
         mov dx,0
	 mov bx,dx
         mov ax,4f05h
         int 10h
         mov cx,32769
         mov si,0
      e1:mov es:[si],di
         inc si
	 inc si
         loop e1
         mov bx,cx
         mov ax,4f05h
         mov dx,1
	 mov cl,byte ptr vesa_WinGranularity
	 shl dx,cl
         int 10h
	 mov cx,32769
         mov si,0
      e2:mov es:[si],di
         inc si
	 inc si
         loop e2
         mov bx,cx
         mov ax,4f05h
         mov dx,2
	 mov cl,byte ptr vesa_WinGranularity
	 shl dx,cl
         int 10h
         mov cx,32769
         mov si,0
      e3:mov es:[si],di
         inc si
	 inc si
         loop e3
         mov bx,cx
         mov ax,4f05h
         mov dx,3
	 mov cl,byte ptr vesa_WinGranularity
	 shl dx,cl
         int 10h
         mov cx,32769
         mov si,0
      e4:mov es:[si],di
         inc si
	 inc si
         loop e4
         mov bx,cx
         mov ax,4f05h
         mov dx,4
	 mov word ptr vesa_bank,dx
	 mov cl,byte ptr vesa_WinGranularity
	 shl dx,cl
	 int 10h
	 mov cx,22528;32769
         mov si,0
      e5:mov es:[si],di
         inc si
	 inc si
         loop e5
         mov di,offset mouse_internal_data
         mov cx,mouse_internal_pixels
      e6:push cx
	 mov ax,ds:[di+2]
         mov bx,640
         mul bx
         add ax,ds:[di]
         adc dx,0
	 mov si,ax
	 cmp word ptr vesa_bank,dx
         je e7
	 mov word ptr vesa_bank,dx
	 mov cl,byte ptr vesa_WinGranularity
	 shl dx,cl
         mov ax,4f05h
         xor bx,bx
         int 10h
      e7:mov al,win_color
         mov ds:[di+5],al
	 mov al,[di+4]
         mov es:[si],al
         add di,6
	 pop cx
         loop e6
         popa
	 sti
         ret
clrscr ENDp
fillrectangle PROC far
	pusha
	mov cx,win_relative_x1
	mov cs:cwin_x,cx
	mov cx,win_relative_y1
	mov cs:cwin_y,cx
	mov cx,win_relative_y2
        sub cx,win_relative_y1
        inc cx
  clsw1:push cx
	mov cx,win_relative_x2
	sub cx,win_relative_x1
	inc cx
  clsw2:push cx
        call putpixel
        pop cx
	inc win_relative_x1
	loop clsw2
	inc win_relative_y1
	mov cx,cs:cwin_x
	mov win_relative_x1,cx
	pop cx
	loop clsw1
	mov cx,cs:cwin_y
	mov win_relative_y1,cx
	popa
	ret
	cwin_x dw 0
	cwin_y dw 0
fillrectangle ENDp

mouse_inst PROC far
     cmp cs:mouse_active,off
     je ppm5
     iret
ppm5:mov cs:mouse_active,on
     pusha
     push ds
     pushf
     mov ax,0
     mov ds,ax
     mov ax,3
     call dword ptr ds:[33h*4]
     ;mov ax,3
     ;int 33h
     mov ax,datasegment
     mov ds,ax
     mov mouse_internal_x1,cx
     mov mouse_internal_y1,dx
     mov mouse_internal_status,bx
        cmp cx,word ptr mouse_internal_data
        jne ppmouse
        cmp dx,word ptr mouse_internal_data+2
        jne ppmouse
        jmp ppm1
ppmouse:push es
	mov ax,0a000h
        mov es,ax
        mov di,word ptr mouse_internal_data
        sub di,mouse_internal_x1
        neg di
        mov si,word ptr mouse_internal_data+2
        sub si,mouse_internal_y1
        neg si
        add mouse_internal_x2,di
        add mouse_internal_y2,si
	mov bx,offset mouse_internal_data
        mov cx,mouse_internal_pixels
	loopmcx:
	  push cx
	  cmp word ptr ds:[bx],639
	  jg lmcxok
	  push di
	  push si
	  push bx
	  mov cx,ds:[bx]
	  mov ax,ds:[bx+2]
	  mov bx,640
	  mul bx
	  add ax,cx
	  adc dx,0
	  mov si,ax
	  cmp word ptr vesa_bank,dx
	  je pm101ha
	  mov word ptr vesa_bank,dx
	  mov cl,byte ptr vesa_WinGranularity
	  shl dx,cl
	  mov ax,4f05h
	  mov bx,0
	  int 10h
	  pm101ha:
	  pop bx
	  mov al,ds:[bx+5] ;color
	  mov es:[si],al
	  pop si
	  pop di
	  lmcxok:
	  add ds:[bx],di
	  add ds:[bx+2],si
	  add bx,6
	  pop cx
	loop loopmcx

	mov word ptr vesa_bank,0ffffh
	mov di,offset mouse_internal_data
        mov cx,mouse_internal_pixels
	loopmcxR:
	push cx
	cmp word ptr ds:[di],639
	jg lmdiokR
        mov ax,ds:[di+2]
        mov bx,640
        mul bx
        add ax,ds:[di]
        adc dx,0
        mov si,ax
	cmp word ptr vesa_bank,dx
	je pm101hbR
	mov word ptr vesa_bank,dx
	mov cl,byte ptr vesa_WinGranularity
	shl dx,cl
        mov ax,4f05h
	mov bl,vesa_WinAAttributes
	mov bh,0
	ror bl,1
	not bl
	and bl,1
        int 10h
	pm101hbR:
	mov al,es:[si]
	mov ds:[di+5],al ;color
lmdiokR:add di,6
	pop cx
	loop loopmcxR

	mov word ptr vesa_bank,0ffffh
	mov di,offset mouse_internal_data
        mov cx,mouse_internal_pixels
	loopmcxW:
	push cx
	cmp word ptr ds:[di],639
	jg lmdiokW
        mov ax,ds:[di+2]
        mov bx,640
        mul bx
        add ax,ds:[di]
        adc dx,0
        mov si,ax
	cmp word ptr vesa_bank,dx
	je pm101hbW
	mov word ptr vesa_bank,dx
	mov cl,byte ptr vesa_WinGranularity
	shl dx,cl
        mov ax,4f05h
        xor bx,bx
        int 10h
	pm101hbW:
	mov al,ds:[di+4]
	mov es:[si],al
lmdiokW:add di,6
	pop cx
	loop loopmcxW
	pop es
   ppm1:pop ds
	popa
        mov cs:mouse_active,off
        iret
        mouse_active db off
mouse_inst ENDp

vesa101h ENDs
